package com.android.stockme.frontend;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class StockDetailsDialog extends Dialog {

	private Dialog stockDetailsDialog = null;
	private TextView currentTxt = null;
	private TextView changeTxt = null;
	private EditText highBoundEdt = null;
	private EditText lowBoundEdt = null;
	private CheckBox highBoundChBox = null;
	private CheckBox lowBoundChBox = null;
	private Button deleteBtn = null;
	private Button applyBtn = null;
	private Button closeBtn = null;

	public StockDetailsDialog(Context context) {
		super(context);
		
		stockDetailsDialog = new Dialog(instance);
		stockDetailsDialog.setContentView(R.layout.stock_details_partial);
		deleteBtn = (Button)stockDetailsDialog.findViewById(R.id.delete_button);
		deleteBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				stockDetailsDialog.dismiss();
				removeStock(v);
			}
		});
		applyBtn = (Button)stockDetailsDialog.findViewById(R.id.apply_button);
		applyBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if (setStockConfiguration())
					stockDetailsDialog.dismiss();
			}			
		});
		closeBtn = (Button)stockDetailsDialog.findViewById(R.id.close_button);
		closeBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				stockDetailsDialog.dismiss();
			}			
		});
		currentTxt = (TextView)stockDetailsDialog.findViewById(R.id.current);
		changeTxt = (TextView)stockDetailsDialog.findViewById(R.id.change);
		highBoundEdt = (EditText)stockDetailsDialog.findViewById(R.id.high_bound_edt);
		lowBoundEdt = (EditText)stockDetailsDialog.findViewById(R.id.low_bound_edt);
		highBoundChBox = (CheckBox)stockDetailsDialog.findViewById(R.id.high_bound_chbox);
		lowBoundChBox = (CheckBox)stockDetailsDialog.findViewById(R.id.low_bound_chbox);
		
		highBoundChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				highBoundEdt.setEnabled(isChecked);
			}
		});
		lowBoundChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				lowBoundEdt.setEnabled(isChecked);
			}
		});
	}

}
